import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import home from './modules/home'
import post from './modules/post'
import * as tokenTools from '@/utils/tokenTools.js'

Vue.use(Vuex)

export const store = new Vuex.Store({
  state: {
    isLogin: tokenTools.getToken() !== '',
    walletAddress: tokenTools.getWalletAddress()
  },
  mutations: {
    setLogin(state, data) {
      state.isLogin = data
    }
  },
  actions: {
    logout({ commit }) {
      tokenTools.clearData()
      commit('setLogin', false)
    },
    login({ commit, dispatch }) {
      commit('setLogin', true)
      dispatch('user/getPorfile')
    }
  },
  modules: {
    user, home, post
  }
})